package br.com.unirio.formula1.visao.modelos;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import br.com.unirio.formula1.servico.ColocacaoEquipe;

public class ModeloClassificacaoGeralEquipe extends AbstractTableModel
{

    /**
     * 
     */
    private static final long serialVersionUID = 259722716995826662L;

    private List<ColocacaoEquipe> li = new ArrayList<ColocacaoEquipe>();
    private String[] columnNames = { "Posicao", "Equipe", "GP 1", "GP 2", "GP 3", "GP 4", "GP 5", "GP 6", "GP 7", "GP 8", "GP 9", "GP 10", "GP 11", "GP 12", "GP 13", "GP 14", "GP 15", "GP 16", "GP 17", "GP 18", "GP 19", "PONTOS" };

    public ModeloClassificacaoGeralEquipe(List<ColocacaoEquipe> list)
    {
	this.li = list;

    }

    @Override
    public String getColumnName(int columnIndex)
    {
	return columnNames[columnIndex];
    }

    @Override
    public int getRowCount()
    {
	return li.size();
    }

    @Override
    public int getColumnCount()
    {
	return this.columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex)
    {

	ColocacaoEquipe colocacaoEquipe = li.get(rowIndex);
	switch (columnIndex)
	{
	    case 0:
		return colocacaoEquipe.getPosicao();
	    case 1:
		return colocacaoEquipe.getEquipe().getNome();
	    case 21:
		return colocacaoEquipe.getTotalPontos();
	    default:
		return colocacaoEquipe.getPontosEmCorrida(columnIndex - 1); // Captura o ID da corrida com base na
									    // posicao do vetor de colunas. A Corrida 1
									    // estara na posicao 3 do vetor.
	}
    }

    @Override
    public Class<?> getColumnClass(int columnIndex)
    {
	switch (columnIndex)
	{
	    case 0:
		return Integer.class;
	    case 1:
		return String.class;
	    case 21:
		return Double.class;
	    default:
		return Double.class;

	}

    }
}
